Skip to content

add support for handling cursor pagination in API 2019-07+ #134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

janmyszkier
Copy link
Contributor

@janmyszkier janmyszkier commented Jan 29, 2020

Adding support for cursor pagination.
example usage:

$productResource =  $shopify->getApi()->Product();
$products = $productResource->get(['limit'=>50]);
$nextPageProducts = $productResource->get($productResource->getNextPageParams());
/* in short: you need to reuse the resource to get the params before making another resource */**

@janmyszkier
Copy link
Contributor Author

@tareqtms can you maybe fix the host on the travis build?

@tareqtms
Copy link
Contributor

tareqtms commented Feb 1, 2020

@janmyszkier
Thanks, I will merge it after reviewing.

@tareqtms tareqtms merged commit 60f9355 into phpclassic:master Feb 16, 2020
@hippoduck
Copy link

hippoduck commented Feb 26, 2020

Adding support for cursor pagination.
example usage:

$productResource =  $shopify->getApi()->Product();
$products = $productResource->get(['limit'=>50]);
$nextPageProducts = $productResource->get($productResource->getNextPageParams());
/* in short: you need to reuse the resource to get the params before making another resource */**

I get the following error when using this example.

Invalid resource name getApi

@tareqtms
Copy link
Contributor

@joeyc002
That was may be some specific code related to his project. Please modify as below:

$productResource =  $shopify->Product();
$products = $productResource->get(['limit'=>50]);
$nextPageProducts = $productResource->get($productResource->getNextPageParams());

@hippoduck
Copy link

hippoduck commented Feb 27, 2020

@joeyc002
That was may be some specific code related to his project. Please modify as below:

$productResource =  $shopify->Product();
$products = $productResource->get(['limit'=>50]);
$nextPageProducts = $productResource->get($productResource->getNextPageParams());

Thanks for this, however the array returned to "$nextPageProducts" is exactly the same as "$products". The same page is returned with both variables. I am using a test shop with 68 products / 300 variants.

$productResource->getNextPageParams() returns an empty array.

@n3o77
Copy link
Contributor

n3o77 commented Feb 27, 2020

@joeyc002 this works fine for me. your problem is probably related to #143

@hippoduck
Copy link

@joeyc002 this works fine for me. your problem is probably related to #143

Ah yes you're right! I changed to 'Link' instead of 'link' in ShopifyResource.php and this is now working.

@hippoduck
Copy link

hippoduck commented Feb 28, 2020

I have got this working now,

`$perPage = 250; // max = 250
$productResource = $this->shopify->Product();
$products = $productResource->get(['limit'=>$perPage]); // gets the first page

do{
$nextPageProducts = $productResource->get($productResource->getNextPageParams()); // grab the next page
$products = array_merge($products, $nextPageProducts); // add the next page to the $products array
}while($productResource->getNextPageParams()); //do while there is a next page
`

@janmyszkier
Copy link
Contributor Author

janmyszkier commented Mar 6, 2020

@joeyc002

$shopify->getApi()

is actually our own wrapper, I should've posted it with clean implementation. But I'm glad you have figured it out 💪

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants